package com.sbd.controller;


import com.sbd.SpringBootDeploymentApplication;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.Extensions;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;


// 驱动Spring Boot Test工作，并指明启动类
@SpringBootTest(
        // 入口类
        classes = SpringBootDeploymentApplication.class,
        // 使用随机端口
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class TestControllerTest {

    // 注入控制器
    @Autowired
    private TestController testController = null;

    // 测试方法
    @Test
    public void testHello() {
        String result = testController.hello("Jim");
        System.out.println(result);
        Assert.notNull(result, "判定结果为空（null）");
    }

    // 注入TestRestTemplate对象
    @Autowired
    private TestRestTemplate restTemplate = null;

    // 测试方法
    @Test
    public void testRestHello() {
        // 简写的URL，无需写出服务器IP和端口
        String url = "/sbd/test/hello/{name}";
        String value = "Jim";
        // 通过REST风格请求获取结果
        String result = restTemplate.getForObject(url, String.class, "Jim");
        System.out.println(result);
        Assert.notNull(result, "判定结果为空（null）");
    }



}
